﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;

namespace org.zx.ms.core.Util {
    public static class ExtensionMethods {

        public static T Clone<T>(this T obj) {
            T result;
            DataContractSerializer dcs = new DataContractSerializer(typeof(T));

            using (MemoryStream ms = new MemoryStream()) {
                dcs.WriteObject(ms, obj);
                ms.Position = 0;
                result = (T)dcs.ReadObject(ms);
            }
            return result;
        }
    }
}
